package com.jshoperxms.components.scheduler;

import com.jshoperxms.controller.utils.DateTools;
import com.jshoperxms.entity.YdTeamT;
import com.jshoperxms.entity.YdTeamTargetT;
import com.jshoperxms.service.YdTeamTargetTService;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by sdywcd on 2019/4/12.
 * Des:
 */
@Component
public class TargetSecheduler {

    private static final org.slf4j.Logger LOGGER =  LoggerFactory.getLogger(TargetSecheduler.class);

    @Resource
    private YdTeamTargetTService ydTeamTargetTService;

    //@Scheduled(cron = "0/10 * * * * ?")//每天0点执行一次结算计算0 0 0 * * ?

    @Scheduled(cron = "0 0 1 * * ?")//每天0点执行一次结算计算0 0 0 * * ?
    public void checkTargetIsFinishOver(){
        LOGGER.info("开始执行每日检查目标是否结束"+DateTools.getSystemTimeLong());
        //获取系统时间
        long currenttimelong=DateTools.getSystemTimeLong();
        Criterion criterion= Restrictions.and(Restrictions.lt("finishtargettime",currenttimelong)).add(Restrictions.ne("targetstatus","2"));
        List<YdTeamTargetT>list=this.ydTeamTargetTService.findByCriteria(YdTeamTargetT.class,criterion);
        for(YdTeamTargetT ydTeamTargetT:list){
            ydTeamTargetT.setTargetstatus("2");//时间到结束
            ydTeamTargetT.setVersiont(ydTeamTargetT.getVersiont()+1);
            ydTeamTargetT.setUpdatetime(DateTools.getSystemTimeLong());
            this.ydTeamTargetTService.update(ydTeamTargetT);
        }
    }
}
